package com.ww.trysomething.kerberos;

import com.sun.deploy.net.HttpResponse;
import org.apache.http.HttpHost;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import sun.net.www.http.HttpClient;

import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.io.InputStream;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {
    public static void main(String[] args) {

        SpnegoHttpClientConfigCallbackHandler callbackHandler = new SpnegoHttpClientConfigCallbackHandler();
        RestClientBuilder restClientBuilder = RestClient.builder(HttpHost.create("https://fusioninsight02:24100"));
        //restClientBuilder.
        restClientBuilder.setHttpClientConfigCallback(callbackHandler);

        try (RestClient restClient = restClientBuilder.build()) {

            Request request = new Request("GET", "/jucun_eoi/_search");
            request.setJsonEntity("{\n" +
                    "    \"query\":{\n" +
                    "        \"match_all\":{}\n" +
                    "    },\n" +
                    "    \"size\":10\n" +
                    "}");
            Response response = restClient.performRequest(request);
            System.out.println(EntityUtils.toString(response.getEntity()));


        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
